package com.ids.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import com.ids.util.DbManager;

public class LeaveStatusDao {
	private static LeaveStatusDao instance = new LeaveStatusDao();

	private LeaveStatusDao() {
	}

	public static LeaveStatusDao getInstance() {
		return instance;
	}
	
	public Map<String , Double> getLeaveStatus(String empCode){
		Map<String , Double> leaveStatusMap = new HashMap<String, Double>();
		DbManager dbManager = new DbManager();
		Connection conn = dbManager.getConnection();
		ResultSet leaveStatusRS = null;
		String leaveStatusSql = "select * from leaveCount where empCode = ?";
		try {
			PreparedStatement prepStmt = conn.prepareStatement(leaveStatusSql);
			prepStmt.setString(1, empCode);
			leaveStatusRS = prepStmt.executeQuery();
			while (leaveStatusRS.next()) {
				leaveStatusMap.put(leaveStatusRS.getString("leaveType"), leaveStatusRS.getDouble("count"));	
			}	
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DbManager.closeResultSet(leaveStatusRS);
			DbManager.closeConnection(conn);
		}
		return leaveStatusMap;
	}

}
